package keepAway.action;

import keepAway.bean.KeepAway;
import keepAway.dao.KeepAwayDao;

import com.opensymphony.xwork2.ActionSupport;

public class KeepAwayAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 9209748354249624737L;
	
	private KeepAwayDao keepAwayDao;
	
	private KeepAway keepAway;
	
	private String discribe;
	
	private String explain;
	
	private String sysFunction;
	
	private Long sysId;

	public Long getSysId() {
		return sysId;
	}

	public void setSysId(Long sysId) {
		this.sysId = sysId;
	}

	public String getExplain() {
		return explain;
	}

	public void setExplain(String explain) {
		this.explain = explain;
	}

	public String getSysFunction() {
		return sysFunction;
	}

	public void setSysFunction(String sysFunction) {
		this.sysFunction = sysFunction;
	}

	public String getDiscribe() {
		return discribe;
	}

	public void setDiscribe(String discribe) {
		this.discribe = discribe;
	}

	public KeepAway getKeepAway() {
		return keepAway;
	}

	public void setKeepAway(KeepAway keepAway) {
		this.keepAway = keepAway;
	}

	public KeepAwayDao getKeepAwayDao() {
		return keepAwayDao;
	}

	public void setKeepAwayDao(KeepAwayDao keepAwayDao) {
		this.keepAwayDao = keepAwayDao;
	}

	@Override
	public String execute() throws Exception {
		
		if(this.sysId!=null&&this.sysId!=0L){
			System.out.println("标号是： "+this.keepAway.getSys_id());
			this.keepAway = this.keepAwayDao.findById(this.sysId);
			
		}
		
		return SUCCESS;
	}
	public String insertContent() throws Exception{
		if(keepAway!=null)
		if((keepAway.getSys_dis().trim()!=null)
				||(keepAway.getSys_explain().trim()!=null)
				||(keepAway.getSys_fun_synopsis().trim()!=null))
		{
			if(this.keepAwayDao.findAll().toString().equals("[]")){
				keepAway.setSys_id(1L);
				this.keepAwayDao.create(keepAway);
			}else {
				keepAway.setSys_id(1L);
				this.keepAwayDao.update(keepAway);
				return INPUT;
			}
			
		}
		return SUCCESS;
	}
	
	public String findDiscribe() throws Exception{
		System.out.println("<<<<<<<<<<<<<<<<<<<<<"+this.keepAwayDao.findAll().toString());
		if(!this.keepAwayDao.findAll().toString().equals("[]")){
			
			this.discribe = this.keepAwayDao.findAll().get(0).getSys_dis();
		}
		return SUCCESS;
	}
	
	public String findExplain() throws Exception{
		if(!this.keepAwayDao.findAll().toString().equals("[]")){
			this.explain = this.keepAwayDao.findAll().get(0).getSys_explain();
		}
		return SUCCESS;
	}
	
	public String findFunction() throws Exception{
		if(!this.keepAwayDao.findAll().toString().equals("[]")){
			this.sysFunction = this.keepAwayDao.findAll().get(0).getSys_fun_synopsis();
		}
		return SUCCESS;
	}
	
	public String updateKeepAway(){
		if(this.keepAway!=null&&this.keepAway.getSys_id()!=0L){
			this.keepAway = this.keepAwayDao.findById(this.keepAway.getSys_id());
		}
		return SUCCESS;
	}
	
	public String displayAllKP(){
		if(!this.keepAwayDao.findAll().toString().equals("[]")){
			this.keepAway = this.keepAwayDao.findAll().get(0);
		}
		return SUCCESS;
	}
}
